package com.chain.BrotherExchange.data.model;

import com.chain.BrotherExchange.C;

public class BaseResponseModel<T> {

    public static BaseResponseModel e(String message) {
        return e(message, C.NETWORK_UNKNOWN_ERROR);
    }

    public static BaseResponseModel e(String message, int code) {
        return new BaseResponseModel(message, code);
    }

    public static BaseResponseModel s() {
        return new BaseResponseModel("成功", C.NETWORK_SUCCESS);
    }

    /**
     * msg : 发送成功
     * code : 0
     * data : {}
     * runtime : 0.108551s
     */

    private String msg;
    private int code;
    private T data;

    public BaseResponseModel() {
    }

    public BaseResponseModel(String msg, int code) {
        this.msg = msg;
        this.code = code;
    }

    public <E extends BaseResponseModel> E error(String message) {
        return error(C.NETWORK_UNKNOWN_ERROR, message);
    }

    public <E extends BaseResponseModel> E error(int code, String message) {
        this.code = code;
        msg = message;
        return (E) this;
    }

    public <E extends BaseResponseModel> E success(String message) {
        code = C.NETWORK_SUCCESS;
        msg = message;
        return (E) this;
    }

    /**
     * 是否没有网络
     */
    public boolean isNotNetwork(){
        return code == C.NETWORK_NOT_NETWORK;
    }

    /**
     * 是否成功
     */
    public boolean isSucceed() {
        return code == C.NETWORK_SUCCESS;
    }

    /**
     * 是否登录失效
     */
    public boolean isLogonFailure() {
        return code == C.NETWORK_LOGON_FAILURE;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
